#include <iostream>
#include <queue>
#include <cstring>
using namespace std;

int N, K;
bool isvisted[100010];
int path[100010];

void bfs()
{
    queue<int> q;
    q.push(N);
    isvisted[N] = true;
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        if (u == K)
        {
            cout << path[u] << endl;
            return;
        }
        for (int i = 0; i < 3; i++)
        {
            int v = u;
            if (i == 1)
                v += 1;
            else if (i == 2)
                v -= 1;
            else
                v *= 2;
            if (v >= 0 && v <= 100000 && !isvisted[v])
            {
                q.push(v);
                path[v] = path[u] + 1;
                isvisted[v] = true;
            }
        }
    }
}

int main()
{
    cin >> N >> K;
    bfs();
    //system("pause");
    return 0;
}
